package com.example.academicsystem.server.service.impl;

import com.example.academicsystem.constant.MessageConstant;
import com.example.academicsystem.exception.QueryFailedException;
import com.example.academicsystem.pojo.dto.GradeCourseOrderDto;
import com.example.academicsystem.pojo.vo.GradeCourseOrderVo;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.server.dao.GradeMapper;
import com.example.academicsystem.server.service.GradeService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GradeServiceImpl implements GradeService {
    @Autowired
    private GradeMapper gradeMapper;

    /**
     * 分页查询某一课程的学生成绩排名
     * */
    public PageResult gradeOrderByCourse(GradeCourseOrderDto gradeCourseOrderDto) {
        if (gradeCourseOrderDto.getCourseId()==null && gradeCourseOrderDto.getCourseName()==null)
            throw new QueryFailedException(MessageConstant.PARAM_NULL);
        PageHelper.startPage(gradeCourseOrderDto.getPage(),gradeCourseOrderDto.getPageSize());
        Page<GradeCourseOrderVo> page = gradeMapper.gradeOrderByCourse(gradeCourseOrderDto);
        return new PageResult(page.getTotal(),page.getResult());
    }
}
